﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace FireBillBook.Core.Models
{
    public class PagingQuery
    {
        public int PageIndex { get; set; }
        public int PageSize { get; set; }

        public PagingModel<T> ConvertToPagingModel<T>()
        {
            return new PagingModel<T>
            {
                PageIndex = this.PageIndex,
                PageSize = this.PageSize
            };
        }

        public IQueryable<T> TryPaging<T>(IQueryable<T> source)
        {
            if(PageIndex >= 0 && PageSize >= 0)
            {
                source = source.Skip((PageIndex - 1) * PageSize).Take(PageSize);
            }

            return source;
        }
    }
}
